package com.chuji.crmcj.adapter;

import android.content.Context;
import android.view.View;
import android.view.ViewGroup;
import android.widget.BaseAdapter;
import android.widget.ImageView;
import android.widget.LinearLayout;
import android.widget.ListView;
import android.widget.TextView;

import com.chuji.crmcj.R;
import com.chuji.crmcj.bean.OrdDelInfo;
import com.chuji.crmcj.utils.NumberUtils;

/**
 * Created by w.pitt on 2016/2/23.
 */
public class OrdDelAdp extends BaseAdapter {

    private Context mContext;
    private OrdDelInfo ordDelInfo;
    private MagViewHoler magHolder;
    private LinearLayout mLlMagOrderDetail;

    public OrdDelAdp(Context context, OrdDelInfo ordDelInfo) {
        this.mContext = context;
        this.ordDelInfo = ordDelInfo;
    }

    @Override
    public int getCount() {
        return ordDelInfo.getApiParamObj().size() == 0 ? 0 : ordDelInfo.getCount();
    }

    @Override
    public Object getItem(int position) {
        return null;
    }

    @Override
    public long getItemId(int position) {
        return 0;
    }

    @Override
    public View getView(int position, View convertView, ViewGroup parent) {
        if (convertView == null) {
            convertView = View.inflate(mContext, R.layout.listview_mag_client_lose, null);
            magHolder = new MagViewHoler();
            mLlMagOrderDetail = (LinearLayout) convertView.findViewById(R.id.ll_mag_order_detail);
            mLlMagOrderDetail.setVisibility(View.VISIBLE);

            magHolder.iv_no_read = (ImageView) convertView.findViewById(R.id.iv_no_read);
            magHolder.tv_client_name = (TextView) convertView.findViewById(R.id.tv_client_name);
            magHolder.tv_car_type = (TextView) convertView.findViewById(R.id.tv_car_type);
            magHolder.tv_client_num = (TextView) convertView.findViewById(R.id.tv_client_num);
            magHolder.tv_want_car = (TextView) convertView.findViewById(R.id.tv_want_car);
            magHolder.tv_salesman_name = (TextView) convertView.findViewById(R.id.tv_salesman_name);
            magHolder.tv_handle_time = (TextView) convertView.findViewById(R.id.tv_handle_time);
            convertView.setTag(magHolder);
        } else {
            magHolder = (MagViewHoler) convertView.getTag();
        }

        if (ordDelInfo.getApiParamObj().get(position).getIsRead() == 0) {
            magHolder.iv_no_read.setVisibility(View.VISIBLE);
        } else {
            magHolder.iv_no_read.setVisibility(View.GONE);
        }

        magHolder.tv_client_name.setText(ordDelInfo.getApiParamObj().get(position).getCustomerName());
        magHolder.tv_car_type.setText(ordDelInfo.getApiParamObj().get(position).getCarModel());
        magHolder.tv_salesman_name.setText(ordDelInfo.getApiParamObj().get(position).getSaleName());
        magHolder.tv_want_car.setText("订单车型");
        magHolder.tv_handle_time.setText(ordDelInfo.getApiParamObj().get(position).getOrderTime());
        String custormerTel = ordDelInfo.getApiParamObj().get(position).getCustormerTel();
        if (custormerTel.length() == 11 || custormerTel.length() == 7) {
            magHolder.tv_client_num.setText(NumberUtils.parsePhoneNumber(custormerTel));
        }
        return convertView;
    }

    static class MagViewHoler {
        private TextView tv_client_name;
        private TextView tv_car_type;
        private TextView tv_client_num;
        private TextView tv_want_car;
        private TextView tv_salesman_name;
        private TextView tv_handle_time;
        private ImageView iv_no_read;

    }
}
